import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/sendJsonServlet")
public class sendJsonServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String user = request.getParameter("j");
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        System.out.println(user);
        //JSON对象
        JSONObject jsonObject = new JSONObject();
        jsonObject.accumulate("password", password).accumulate("name", "www");
        response.setContentType("application/json");
        response.getWriter().write(jsonObject.toString());
    }
}
